package com.wanxi.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    private static final String TOPIC_EXCHANGE = "wx_centerExchange";

    @Bean
    public Queue managerQueue() {
        // 如果rabbit 里没有这个队列，会创建该队列
        return new Queue("wx_contact",true);
    }


    @Bean
    TopicExchange wxInHomeTopicExchange() {
        // 如果rabbit 里没有这个exchange，则会创建一个
        return new TopicExchange(TOPIC_EXCHANGE,true,false);
    }

    /**
     * 绑定队列到 wx.centerExchange
     * "#"匹配多个单词
     * "*"匹配一个单词
     */
    @Bean
    Binding hrQueue2WxInHomeTopic() {
        // 绑定队列到topic. 这里的routingKey是binding key.
        return BindingBuilder.bind(managerQueue()).to(wxInHomeTopicExchange()).with("contact.#");
    }


}